package com.kaibes.core.spring.bean;

import java.util.Arrays;

public class BeanFilterHelper {
    
    public static BeanFilter addNotField(BeanFilter filter, String... notFields) {
        if (filter == null) {
            filter = new BeanFilter();
            filter.setIncluded(false);
            filter.setFields(Arrays.asList(notFields));
        } else {
            if (filter.isIncluded()) {
                for (String field : notFields) {
                    if (filter.getFields().contains(field)) {
                        filter.getFields().remove(field);
                    }
                }
            } else {
                for (String field : notFields) {
                    if (!filter.getFields().contains(field)) {
                        filter.getFields().add(field);
                    }
                }
            }
        }
        return filter;
    }
}
